package com.hourse.app.controller.web;

import com.hourse.app.service.PlatformAccountService;
import com.hourse.app.vo.web.BalanceRetVo;
import com.hourse.app.vo.web.OrdersRetVo;
import com.hourse.okx.config.APIConfiguration;
import com.hourse.platform.utils.AppTools;
import com.hourse.platform.vo.PageData;
import com.hourse.platform.vo.ResultMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @作者 ：lichenguang
 * @描述 ：【平台账号信息】
 * @创建 ：2022/3/21 15:19
 */
@Api(tags = "用户端-账户服务")
@RestController
@RequestMapping("web/platform/account")
@Slf4j
public class WebAccountController {

  @Autowired
  private PlatformAccountService platformAccountService;

  @ApiOperation(value = "查询-当前币种委托订单")
  @SneakyThrows
  @GetMapping(value = "findNowOrders")
  public PageData findNowOrders(@RequestParam(name = "currency") String currency) {

    APIConfiguration config = platformAccountService.getConfig(AppTools.GetCurrentUserId());
    List<OrdersRetVo> list = platformAccountService.findNowOrders(config, currency);

    return new ResultMsg<>(list);
  }

  @ApiOperation(value = "查询-历史委托")
  @SneakyThrows
  @GetMapping(value = "findHistoryOrders")
  public PageData findHistoryOrders(@RequestParam(name = "currency") String currency) {

    APIConfiguration config = platformAccountService.getConfig(AppTools.GetCurrentUserId());
    List<OrdersRetVo> list = platformAccountService.findHistoryOrders(config, currency);

    return new ResultMsg<>(list);
  }

  @ApiOperation(value = "查询-币种资产(余额)")
  @SneakyThrows
  @GetMapping(value = "findBalance")
  public PageData findBalance(@RequestParam(name = "currency") String currency) {

    APIConfiguration config = platformAccountService.getConfig(AppTools.GetCurrentUserId());
    List<BalanceRetVo> balance = platformAccountService.findBalance(config, "");

    return new ResultMsg<>(balance);
  }

  @ApiOperation(value = "查询-USDT账户余额")
  @SneakyThrows
  @GetMapping(value = "findUsdtBalance")
  public PageData findUsdtBalance() {

    APIConfiguration config = platformAccountService.getConfig(AppTools.GetCurrentUserId());
    List<BalanceRetVo> balance = platformAccountService.findBalance(config, "USDT-SWAP");

    return new ResultMsg<>(balance);
  }

}
